//
//  DLControlViewController.m
//  DLSport
//
//  Created by DongL on 2017/4/24.
//  Copyright © 2017年 DongL. All rights reserved.
//

#import "DLControlViewController.h"
#import "DLSportTrackViewController.h"


@interface DLControlViewController ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *continueConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *finishConstraint;
@property (weak, nonatomic) IBOutlet UIButton *pauseBtn;

@property (nonatomic, strong) DLSportTrackViewController *trackVc;
@property (weak, nonatomic) IBOutlet UILabel *totalDistance;
@property (weak, nonatomic) IBOutlet UILabel *tatalTime;
@property (weak, nonatomic) IBOutlet UILabel *avgSpeed;


@end

@implementation DLControlViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    _trackVc = [[DLSportTrackViewController alloc] init];
    _trackVc.track = _track;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(locationDidUpdateNote) name:@"DLSportLocationDidUpdateNote" object:nil];
    
}

- (void)locationDidUpdateNote {
    
    //设置数据
    self.totalDistance.text = [NSString stringWithFormat:@"%.2f", _trackVc.mapVc.totalDistance];
    int time = (int) _trackVc.mapVc.totalTime;
    self.tatalTime.text = [NSString stringWithFormat:@"%02d:%02d:%02d", time / 3600, (time % 3600) / 60, time % 60];
    self.avgSpeed.text = [NSString stringWithFormat:@"%.2f", _trackVc.mapVc.avgSpeed];
    
}

- (IBAction)presentVc:(id)sender {
    
    [self presentViewController:_trackVc animated:YES completion:nil];
    
}
- (IBAction)controlBtnClick:(UIButton *)sender {
    
    self.track.sportState = sender.tag;
    
    switch (sender.tag) {
        case DLSportStatePause:
        {
            //继续按钮左偏
            self.continueConstraint.constant -= 90;
            //结束按钮右偏
            self.finishConstraint.constant += 90;
            //隐藏暂停按钮
            self.pauseBtn.hidden = YES;
            [UIView animateWithDuration:0.25 animations:^{
                [self.view layoutIfNeeded];
            }];
        }
            break;
        case DLSportStateContinue:
        {
            //继续按钮右偏
            self.continueConstraint.constant += 90;
            //结束按钮左偏
            self.finishConstraint.constant -= 90;
            
            [UIView animateWithDuration:0.25 animations:^{
                [self.view layoutIfNeeded];
            } completion:^(BOOL finished) {
                
                //显示暂停按钮
                self.pauseBtn.hidden = NO;
            }];
        }
            break;
            
        default:
            break;
    }

    
    
}

@end
